package com.ssm.icc.card.dao.mapper.record;

import com.github.pagehelper.PageInfo;
import com.jee.ssm.common.web.param.ParamMap;
import com.ssm.icc.card.dao.model.record.Record;
import com.ssm.upms.dao.mapper.ssm.LzDao;
import org.apache.ibatis.session.RowBounds;
import org.springframework.stereotype.Repository;

import java.util.List;
import java.util.Map;

/**
* 开门记录管理 Dao
* @author GaoXiang
* @version 1.0
*/
@Repository
public class RecordDao extends LzDao<Record> {



    /**
    * 保存数据
    * @param record 实体对象
    * @return 实体id
    * @throws Exception 数据保存异常
    */
    public Integer insert(Record record) throws Exception {
        return insert("RecordMapper.insert",record);
    }

    /**
    * 根据 id 修改
    * @param record 带id的实体对象
    * @return 受影响的行数
    * @throws Exception 数据修改异常
    */
    public Integer updateById(Record record) throws Exception {
        return update("RecordMapper.updateById",record);
    }

    /**
    * 根据 id 删除
    * @param id 数据id
    * @return 受影响的行数
    * @throws Exception 数据删除异常
    */
    public Integer deleteById(String id) throws Exception {
        return delete("RecordMapper.deleteById",id);
    }

    /**
    * 根据 id 查找
    * @param id 实体id
    * @return 实体
    */
    public Record selectById(String id) {
        return selectOne("RecordMapper.selectById",id);
    }

    /**
    * 根据 id 批量删除
    * @param ids 要删除的id
    * @return 影响的行数
    * @throws Exception 数据删除异常
    */
    public Integer deleteByIds(List<String> ids) throws Exception {
        return delete("RecordMapper.deleteByIds",ids);
    }

    /**
    * 查询列表
    * @param map 参数
    * @return 列表
    */
    public PageInfo<Record> list(Map map) {
        return list("RecordMapper.list",map);
    }

    /**
    * 查询列表 带分页
    * @param map 参数
    * @param page 页码
    * @param size 每页大小
    * @return 列表
    */
    public PageInfo<Record> list(Map map, int page, int size) {
        return list("RecordMapper.list",map,new RowBounds(page,size));
    }

    public PageInfo<Record> selectByEgcardId3(Map map, int page, int size) {
        return list("RecordMapper.selectByEgcardId3",map,new RowBounds(page,size));
    }

    /**
     * 查询列表
     * @param record 参数
     * @return 列表
     */
    public List<Record> selectByEgcardId(Record record) {
        return arrayList("RecordMapper.selectByEgcardId", record);
    }


    /**
     * 查询列表
     * @param record 参数
     * @return 列表
     */
    public List<Record> selectByEgcardId2(Record record) {
        return arrayList("RecordMapper.selectByEgcardId2",record);
    }

    /**
     * 查询开门记录信息
     * @param map
     * @return
     */
    public List<Record>  listAll(Map map){return  arrayList("RecordMapper.listAll",map);}

    /**
     * 获取最后一次刷卡记录
     * @param map 门禁卡的id
     * @return 实体
     */
    public List<Record> countLastCard(Map map){return  arrayList("RecordMapper.countLastCard",map);}

    public Record countLast(String id){return  selectOne("RecordMapper.countLast",id);}

    /**
     * 统计最后一次刷卡的时间
     * @param map
     * @return 行数
     */
    public  Long countTime(Map map){return  count("RecordMapper.countTime",map);}

    /**
     * 根据设备id 查询开门记录
     * @param paramMap
     * @return
     */
    public List<Record> recordByequipmentId(ParamMap paramMap) {
        return arrayList("RecordMapper.recordByequipmentId",paramMap);
    }

    public PageInfo<Record> listRecord(ParamMap paramMap, Integer page, Integer size) {
        return list("RecordMapper.listRecord",paramMap,new RowBounds(page,size));
    }

    /**
     * 查询某房间的开门列表 带分页
     * @param record 参数
     * @return 列表
     */
    public List<Record> openList(Record record) {
        return arrayList("RecordMapper.openList",record);
    }


    public List<Record> countName(ParamMap paramMap) {
        return arrayList("RecordMapper.countName",paramMap);
    }

    public Record countNumber(ParamMap paramMap) {
        return selectOne("RecordMapper.countNumber",paramMap);
    }

    public Record countHourRecord(ParamMap paramMap) {
        return selectOne("RecordMapper.countHourRecord",paramMap);
    }
    public Record countLastUser(String id){return  selectOne("RecordMapper.countLastUser",id);}
}
